package com.xbongbong.paas.elasticsearch.model;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.elasticsearch.pojo.dto.AssociationListDataDTO;
import com.xbongbong.paas.elasticsearch.pojo.vo.FormDataRepeatBatchVO;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.UpdateByQueryDTO;
import com.xbongbong.paas.pojo.vo.AssociationListDataVO;
import com.xbongbong.paas.pojo.vo.FormDataRepeatVO;
import com.xbongbong.paas.pojo.vo.LinkSearchListVO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.vo.LinkQueryVO;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderDataEsListVO;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.data.domain.PageRequest;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * 表单数据es 核心逻辑
 * @author kaka
 * @time 2018-9-18 13:43
 */
public interface PaasFormDataEsModel {

    /**
     * 插入
     * @param paasFormDataEntity
     * @return
     * @throws XbbException
     */
    void insert(PaasFormDataEntity paasFormDataEntity ) throws XbbException;

    /**
     * 插入
     * @param paasFormDataEntity
     * @return
     * @throws XbbException
     */
    void insert(PaasFormDataEntity paasFormDataEntity, WriteRequest.RefreshPolicy refreshPolicy ) throws XbbException;

    /**
     * 批量插入
     * @param paasFormDataEntityList
     */
    void insertBatch(List<PaasFormDataEntity> paasFormDataEntityList ) throws XbbException;

    /**
     * 更新
     * @param paasFormDataEntity
     * @throws XbbException
     */
    void update(PaasFormDataEntity paasFormDataEntity ) throws XbbException;

    /**
     * 批量更新
     * @param paasFormDataEntityList
     * @throws XbbException
     */
    void updateBatch(List<UpdateDataEntity> paasFormDataEntityList) throws XbbException;
    /**
     * 批量更新
     * @param list
     * @throws XbbException
     */
    void updateBatch(List<UpdateDataEntity> list, WriteRequest.RefreshPolicy refreshPolicy)  throws XbbException;
    /**
     * 根据ID批量更新, 更新内容在Map里
     * @param list
     * @param corpid
     * @param map
     * @throws XbbException
     */
    void updateBatch(List<Long> list, String corpid, Map<String,Object> map) throws XbbException;

    /**
     * 删除（del=1）
     * @param key
     * @param corpid
     * @throws ExecutionException
     * @throws InterruptedException
     */
    void delete(Long key, String corpid) throws IOException, XbbException;
    /**
     * 查看数据列表
     * @param formDataListDTO
     * @return
     * @throws XbbException
     */
    PaasFormDataEsListVO list(FormDataListDTO formDataListDTO, IndexTypeEnum indexTypeEnum) throws XbbException;

    SearchRequest getSearchRequest(FormDataListDTO formDataListDTO, IndexTypeEnum indexTypeEnum, SearchSourceBuilder sourceBuilder) throws XbbException;

    SearchRequest getSearchRequest(FormDataListDTO formDataListDTO, IndexTypeEnum indexTypeEnum, SearchSourceBuilder sourceBuilder, BoolQueryBuilder boolQueryBuilder) throws XbbException;

    /**
     * 查看工单数据列表
     * @param formDataListDTO
     * @return
     * @throws XbbException
     */
    WorkOrderDataEsListVO workOrderList(FormDataListDTO formDataListDTO) throws XbbException;
    /**
     * es关联查询
     * @param
     * @param page
     * @param pageSize
     * @return
     * @throws XbbException
     */
    LinkSearchListVO filterLinkSearch(PageRequest pageRequest, SearchRequest searchRequest, Integer page, Integer pageSize) throws XbbException;



//    void agg(Integer key, String corpid) throws XbbException;

    /**
     * 获取总记录数
     * @param searchRequest
     * @return
     */
    Long count(SearchRequest searchRequest) throws XbbException;

    /**
     * 查询相同数据
     * @param
     * @return
     * @throws XbbException
     */
    FormDataRepeatVO repeat(PageRequest pageRequest, SearchRequest searchRequest) throws XbbException;

    /**
     * 批量查重
     * @param
     * @return
     * @throws XbbException
     */
    FormDataRepeatBatchVO repeatBatch(PageRequest pageRequest, SearchRequest searchRequest) throws XbbException;

    /**
     * 根据i查询条件更新
     * @param updateByQueryDTO
     * @throws XbbException
     */
    @Deprecated
    void updateByQuery(UpdateByQueryDTO updateByQueryDTO)  throws XbbException;

    /**
     * 获取关联列表的数据
     * @param associationListDataDTO 对象
     * @param indexTypeEnum
     * @return 关联列表的数据
     * @throws XbbException
     */
    AssociationListDataVO associationListDataList(AssociationListDataDTO associationListDataDTO, IndexTypeEnum indexTypeEnum) throws XbbException;

    void updateBatch(List<Long> dataIdList, String corpid, Map<String,Object> map, IndexTypeEnum idxSaasCustomer) throws XbbException;

    /**
     * 查看回/付款单数据列表
     * @param formDataListDTO
     * @param indexTypeEnum 索引类型
     * @return
     * @throws XbbException
     */
    PaasFormDataEsListVO sheetList(FormDataListDTO formDataListDTO, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * @param idIn
     * @param corpid
     * @param saasMark
     * @param businessType
     * @param fieldList
     * @param indexTypeEnum
     * @return java.util.List<com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt>
     * @author 吴峰
     * @date 2020/10/23 15:15
     * @throws XbbException       
     */
    List<PaasFormDataEntityExt> getByIdList(List<Long> idIn, String corpid, Integer saasMark, Integer businessType, List<String> fieldList, IndexTypeEnum indexTypeEnum) throws XbbException;
    /**
     * 根据data里某个条件搜索
     *
     * @param businessType 业务类型
     * @param attr   data里属性
     * @param value  data里属性的值
     * @param param 参数
     * @author 吴峰
     * @return java.util.List<com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt>
     * @date 2020/10/26 9:04
     * @throws XbbException
     */
    List<PaasFormDataEntityExt> selectByOneCondition(Integer businessType, String attr, Object value, Map<String,Object> param, IndexTypeEnum indexTypeEnum) throws XbbException;
    /**
     * 根据data里某个条件搜索
     *
     * @param businessType 业务类型
     * @param dataParam   data里属性
     * @param param 参数
     * @author 吴峰
     * @return java.util.List<com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt>
     * @date 2020/10/26 9:04
     * @throws XbbException
     */
    List<PaasFormDataEntityExt> selectByCondition(Integer businessType,Map<String, Object> dataParam, Map<String,Object> param, IndexTypeEnum indexTypeEnum) throws XbbException ;

}
